package com.bpmn.flow.behavior;

import lombok.Setter;
import org.flowable.bpmn.model.Activity;
import org.flowable.bpmn.model.UserTask;
import org.flowable.engine.impl.bpmn.behavior.AbstractBpmnActivityBehavior;
import org.flowable.engine.impl.bpmn.behavior.ParallelMultiInstanceBehavior;
import org.flowable.engine.impl.bpmn.behavior.SequentialMultiInstanceBehavior;
import org.flowable.engine.impl.bpmn.behavior.UserTaskActivityBehavior;
import org.flowable.engine.impl.bpmn.parser.factory.DefaultActivityBehaviorFactory;

/**
 * 自定义的 ActivityBehaviorFactory 实现类，目的如下：
 * 1. 自定义 {@link #createUserTaskActivityBehavior(UserTask)}：实现自定义的流程任务的 assignee 负责人的分配
 *
 * @author rain
 */
@Setter
public class BpmActivityBehaviorFactory extends DefaultActivityBehaviorFactory {

    private BpmTaskCandidateInvoker taskCandidateInvoker;

    @Override
    public UserTaskActivityBehavior createUserTaskActivityBehavior(UserTask userTask) {
        BpmUserTaskActivityBehavior behavior = new BpmUserTaskActivityBehavior(userTask);
        behavior.setTaskCandidateInvoker(taskCandidateInvoker);
        return behavior;
    }

    @Override
    public ParallelMultiInstanceBehavior createParallelMultiInstanceBehavior(Activity activity, AbstractBpmnActivityBehavior behavior) {
        BpmParallelMultiInstanceBehavior instanceBehavior = new BpmParallelMultiInstanceBehavior(activity, behavior);
        instanceBehavior.setTaskCandidateInvoker(taskCandidateInvoker);
        return instanceBehavior;
    }

    @Override
    public SequentialMultiInstanceBehavior createSequentialMultiInstanceBehavior(Activity activity, AbstractBpmnActivityBehavior behavior) {
        BpmSequentialMultiInstanceBehavior instanceBehavior = new BpmSequentialMultiInstanceBehavior(activity, behavior);
        instanceBehavior.setTaskCandidateInvoker(taskCandidateInvoker);
        return instanceBehavior;
    }

}
